//
//  KZLoginBindPhoneVC.swift
//  BoyeStore
//
//  Created by 朱凯 on 2018/6/23.
//  Copyright © 2018年 itboye. All rights reserved.
//

import UIKit

class KZLoginBindPhoneVC: KZBaseViewController {

    // MARK: ------ property
    // view
    private let loginView: KZLoginOperationView = KZLoginOperationView(inputTexts: ["手机号码", "请输入验证码", "邀请人手机号(非必填)"])
    
    
    // MARK: ------ 生命周期
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "登录"
        self.addBackItem()
        
        createViews()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        setNavigationBackgroungAttributes(naviTranslucent: true, naviBgColor: kThemeColor)
    }
    
    
    // MARK: ------ 创建视图
    func createViews() {
        
        // 顶部淡绿色背景
        let topBgView = UIView()
        topBgView.backgroundColor = kThemeColor
        self.view.addSubview(topBgView)
        topBgView.snp.makeConstraints { (make) in
            make.top.right.left.equalTo(view)
            make.height.equalTo(topBgView.snp.width).multipliedBy(559.0/750.0)
        }
        
        // 登录操作视图
        self.view.addSubview(loginView)
        loginView.snp.makeConstraints { (make) in
            make.top.equalTo(H(110))
            make.left.equalTo(W(15))
            make.right.equalTo(-W(15))
            // height由内部视图决定
        }
        
        // 按钮
        let beginButton = UIButton(type: .custom)
        beginButton.addTarget(self, action: #selector(onLogin), for: .touchUpInside)
        beginButton.layer.cornerRadius = 4
        beginButton.layer.masksToBounds = true
        beginButton.titleLabel?.font = kFont(15)
        beginButton.setTitle("开启特惠", for: .normal)
        beginButton.backgroundColor = kThemeColor
        beginButton.setTitleColor(UIColor.white, for: .normal)
        view.addSubview(beginButton)
        beginButton.snp.makeConstraints { (m) in
            m.left.equalTo(W(30))
            m.right.equalTo(W(-30))
            m.top.equalTo(loginView.snp.bottom).offset(H(40))
            m.height.equalTo(H(40))
        }
      
        
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        print(loginView.inputValues)
    }
    
}


extension KZLoginBindPhoneVC {
    
    @objc private func onLogin() {
        self.view.window?.rootViewController = KZBaseTabBarController()
    }
}
